package spring;

import java.io.FileNotFoundException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.stream.XMLStreamException;

import spring.beanDefinition.BeanDefinition;
import spring.xmlParser.ParserType;
import spring.xmlParser.XmlParser;
import spring.xmlParser.parserImplementations.StAXParser;

@SuppressWarnings("restriction")
public class XmlBeanDefinitionReader {
	
	private ParserType parserType = ParserType.DOM;
	
	private boolean validating;
	
	private Logger logger = Logger.getLogger(XmlBeanDefinitionReader.class.getName());
	
	private XmlParser parser;
	
	public Map<String, BeanDefinition> loadBeansDefinition(String fileName)
		throws FileNotFoundException{
		
		switch(parserType){
		case StAX:
			parser = new StAXParser();
			break;
		default:
			logger.log(Level.SEVERE, "Parser type is not implemented");
			return null;
		}
		
		try {
			return parser.parse(fileName);
		} catch (XMLStreamException e) {
			logger.log(Level.SEVERE, e.getMessage());
			return null;
		}
		
	}
	
	public void setValidating(boolean validating){
		this.validating = validating;
	}
	
	public void setParserType(ParserType parserType){
		this.parserType = parserType;
	}
}
